package com.example.expression;

import com.example.domain.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("ex")
public class ExpressionRoot {

    public boolean hasAuthority(String authority){
        //获取当前登录人权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginuser = (LoginUser) authentication.getPrincipal();
        List<String> permissions = loginuser.getPermissions();
        System.out.println("访问的是自己的ExpressionRoot");
        //判断有没有接口上的权限字符串
        return permissions.contains(authority);
    }
}
